package com.example.lotterysystem.dao.mapper;

import com.example.lotterysystem.dao.dataobject.ActivityDO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ActivityMapper {

    @Insert("insert into activity (activity_name, description, status) " +
            "values (#{activityName}, #{description}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int insert(ActivityDO activityDO);

    @Select("<script> " +
            "   select count(1) from activity " +
            "   <if test=\"activityName!=null\"> " +
            "       where activity_name like concat('%', #{activityName}, '%' ) " +
            "   </if> " +
            "</script>")
    int count(@Param("activityName") String activityName);

    @Select("<script> " +
            "select * from activity " +
            "   <if test=\"activityName!=null\"> " +
            "       where activity_name like concat('%', #{activityName}, '%' ) " +
            "   </if> " +
            "order by id desc limit #{offset}, #{pageSize} " +
            "</script>" )
    List<ActivityDO> selectActivityList(@Param("offset") Integer offset, @Param("pageSize") Integer pageSize, @Param("activityName") String activityName);

    @Select("select * from activity where id = #{id}")
    ActivityDO selectById(@Param("id") Long activityId);

    @Update("update activity set status = #{status} where id = #{id}")
    void updateStatus(@Param("id") Long id, @Param("status") String status);
}
